package ch.fhnw.swa.team42.controller;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

import ch.fhnw.swa.team42.business.PersonEJB;
import ch.fhnw.swa.team42.domain.Person;

@Named
@RequestScoped
public class PersonController {
	public PersonController() {
	}
	// Variablen
	private Person person = new Person();
	@EJB
	private PersonEJB personEJB;
	private List<Person> personList = new ArrayList<Person>();
	
	public Person getPerson() {
		return person;
	}
	
	public void setPerson(Person person) {
		this.person = person;
	}
	
	public List<Person> getPersonList() {
		personList = personEJB.findAllPersons();
		return personList;
	}
	
	public String doCreatePerson() {
		person = personEJB.createPerson(person);
		personList = personEJB.findAllPersons();
		return "CreateErfolgreich";
		
	}
	
    public String shouldCreateBook() {
        return "weiterleitungPerson";
    }
	
	public String doEditPerosn() {
		personEJB.editPerson(person);
		personList = personEJB.findAllPersons();
		return "EditErfolgreich";
	}
	
	public String doDeletePerson() {
		personEJB.deletePerson(person);
		personList = personEJB.findAllPersons();
		return "DeleteErfolgreich";
	}
	
	public void doFindPersonByID(Long personID) {
		person = personEJB.findPersonByID(personID);
	}

}
